var id = window.localStorage.getItem("backstage-access-userId");

$(function() {
  $(".form").getFormTwo({
    id: id
  }, function(data) {
  });

  //提交
  $("body").on("click", "#save-btn", function(event) {
    event.preventDefault();
    var success = $('.form').validate('submitValidate');

    var passwordLength = $("#password").val().length;
    var isRightPass;
    if (passwordLength >= 6 && passwordLength <= 24) {
      isRightPass = true;
    } else {
      isRightPass = false;
    }
    
    if (success) {
      if (isRightPass) {
        //验证通过提交表单
        submitFom();
      } else {
        ly.toast("密码输入有误，请检查密码位数是否为6~24位");
      }
    }
  })

});

/*
 * 提交表单
 */
function submitFom() {
  var userName = $("#userName").val();
  var password = $("#password").val();

  var obj = {};
  var url = site.apiUrl + "/accountManager/addAdminAccount";
	obj = {
		'userName': userName,
    'password': password,
    'id': id
  };
  request({
    url: url,
    data: obj,
    type: "get",
    callback: function(f) {
      if (f.code == 200) {
        ly.alert('修改成功', function() {
          window.location.reload();
        });
      } else {
        ly.toast(f.msg);
      }
    }
  });
}